home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Pascal <--> C string conversion
- ;
- ; Written by Gerard J. van der Land
- ;
- ; Copyright (C) 1992 Gerard J. van der Land. All rights reserved.
- ;
- ; Last updates: 12-Oct-92
- ;
- ; prototypes:
- ;
- ; void pascal c2p(char far *dest, const char far *src, byte max);
- ; void pascal p2c(char far *dest, const char far *src, byte max);
- ;
-
- .MODEL COMPACT
-
- .CODE
-
- public C2P
- public P2C
-
- C2P proc near
- push bp
- mov bp, sp
- push si
- mov bx, di
- mov dx, ds
- les di, [bp+6] ; ES:DI = src
- xor ax, ax
- mov cx, 0FFFFh
- repnz scasb
- not cx
- dec cx ; CX = strlen(src)
- mov al, [bp+4] ; AX = max (AH is still zero)
- cmp cx, ax
- jb c2p_copy
- mov cx, ax ; if (CX >= max) CX = max
- c2p_copy:
- lds si, [bp+6] ; DS:SI = src
- les di, [bp+10] ; ES:DI = dest
- mov al, cl
- stosb
- shr cx, 1
- rep movsw
- adc cx, cx
- rep movsb
- mov ds, dx
- mov di, bx
- pop si
- pop bp
- ret 10
- C2P endp
-
- P2C proc near
- push bp
- mov bp, sp
- push si
- push di
- push ds
- lds si, [bp+6] ; DS:SI = src
- lodsb
- xor ch, ch
- mov cl, al ; CX = Length(src)
- mov bh, ch
- mov bl, [bp+4] ; BX = max
- cmp cx, bx
- jb p2c_copy
- mov cx, bx ; if (CX >= max) CX = max
- p2c_copy:
- mov dx, cx
- les di, [bp+10] ; ES:DI = dest
- shr cx, 1
- rep movsw
- adc cx, cx
- rep movsb
-
- mov ax, cx
- mov cx, bx
- sub cx, dx
- inc cx
- shr cx, 1
- rep stosw ; Fill unused bytes with NULs
- adc cx, cx
- rep stosb
-
- pop ds
- pop di
- pop si
- pop bp
- ret 10
- P2C endp
-
- END